package com.gt.contant;

import org.apache.commons.lang3.StringUtils;

/**
 * 异常处理
 *
 **/
public class CmdCodeException extends RuntimeException {

    /**
     * 枚举异常
     */
    private AjaxCode ajaxCode;

    /**
     * 异常信息,用于替换AjaxCode中的异常信息
     */
    private String message;

    public CmdCodeException(AjaxCode ajaxCode) {
        this.ajaxCode = ajaxCode;
        if (ajaxCode!=null) {
            this.message = ajaxCode.getMessage();
        }
    }

    public CmdCodeException(AjaxCode ajaxCode, String message) {
        this.ajaxCode = ajaxCode;
        this.message = message;
    }

    public AjaxCode getAjaxCode() {
        return this.ajaxCode;
    }

    @Override
    public String getMessage() {
        if (StringUtils.isBlank(this.message)) {
            return this.ajaxCode.getMessage();
        }
        return this.message;
    }
}
